#include<vector>
using namespace std;
class MyCircularDeque {
private:
    vector<int> data;
    int begin = 0;
    int end = 0;
    int size = 0;
    int cap = 0;
public:
    /** Initialize your data structure here. Set the size of the deque to be k. */
    MyCircularDeque(int k):data(k),size(k) {

    }

    /** Adds an item at the front of Deque. Return true if the operation is successful. */
    bool insertFront(int value) {
        if (isFull()) return false;
        begin = (begin - 1 + size) % size;
        data[begin] = value;
        ++cap;
        return true;
    }

    /** Adds an item at the rear of Deque. Return true if the operation is successful. */
    bool insertLast(int value) {
        if (isFull()) return false;
        data[end] = value;
        end = (end + 1) % size;
        ++cap;
        return true;
    }

    /** Deletes an item from the front of Deque. Return true if the operation is successful. */
    bool deleteFront() {
        if (isEmpty()) return false;
        begin = (begin + 1) % size;
        --cap;
        return true;
    }

    /** Deletes an item from the rear of Deque. Return true if the operation is successful. */
    bool deleteLast() {
        if (isEmpty()) return false;
        end = (end - 1 + size) % size;
        --cap;
        return true;
    }

    /** Get the front item from the deque. */
    int getFront() {
        if (isEmpty()) return -1;
        return data[begin];
    }

    /** Get the last item from the deque. */
    int getRear() {
        if (isEmpty()) return - 1;
        int index = (end - 1 + size) % size;
        return data[index];
    }

    /** Checks whether the circular deque is empty or not. */
    bool isEmpty() {
        return cap == 0;
    }

    /** Checks whether the circular deque is full or not. */
    bool isFull() {
        return cap == size;
    }
};

/**
 * Your MyCircularDeque object will be instantiated and called as such:
 * MyCircularDeque* obj = new MyCircularDeque(k);
 * bool param_1 = obj->insertFront(value);
 * bool param_2 = obj->insertLast(value);
 * bool param_3 = obj->deleteFront();
 * bool param_4 = obj->deleteLast();
 * int param_5 = obj->getFront();
 * int param_6 = obj->getRear();
 * bool param_7 = obj->isEmpty();
 * bool param_8 = obj->isFull();
 */